package gov.kqqzyyy.monkey.radiologyscreen.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.Collections;
import java.util.List;

import gov.kqqzyyy.monkey.radiologyscreen.R;
import gov.kqqzyyy.monkey.radiologyscreen.object.FSK_Patients;

/**
 * Created by Monkey on 2017/11/25.
 * B超病人列表适配器
 */

public class MyPatientAdapter extends BaseAdapter {

    private List<FSK_Patients> dataList;
    private LayoutInflater inflater;

    public MyPatientAdapter(Context context) {
        inflater = LayoutInflater.from(context);
    }

    public void setDataList(List<FSK_Patients> list) {
        this.dataList = list;
        Collections.sort(dataList, (arg0, arg1) -> arg0.getAuditTime().compareTo(arg1.getAuditTime()));
        notifyDataSetChanged();
    }

    public List<FSK_Patients> getDataList() {
        return dataList;
    }

    @Override
    public int getCount() {
        if (dataList != null) {
            return dataList.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if (dataList != null && dataList.get(position) != null) {
            return dataList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_patient_info, parent, false);
            holder.patientName = convertView.findViewById(R.id.item_patient_name);
            holder.patientType = convertView.findViewById(R.id.item_patient_type);
            holder.patientTime = convertView.findViewById(R.id.item_patient_time);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (dataList != null) {
            FSK_Patients FSKPatients = dataList.get(position);
            if (FSKPatients != null) {
                holder.patientName.setText(FSKPatients.getPatientName());
                holder.patientType.setText(FSKPatients.getExamineType());
                holder.patientTime.setText(FSKPatients.getAuditTime());
            }
        }
        return convertView;
    }

    private class ViewHolder {
        TextView patientName;
        TextView patientType;
        TextView patientTime;
    }
}
